﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Reflection;

namespace Bluetooth_Fan
{
    public partial class DebugForm : Form
    {
        BleFan_MainForm MainForm;
        public DebugForm()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 重新写一个实例化  为了能在程序一运行就订阅此事件
        /// </summary>
        /// <param name="FormFu"></param>
        public DebugForm(Form FormFu)
        {
            InitializeComponent();
            MainForm = (BleFan_MainForm)FormFu;
            //订阅事件
            MainForm.PlayDebugString += AddDebugLog;
            //  MainForm.PlayDebugString

        }

        private void LOGClrButt_Click(object sender, EventArgs e)
        {
            DebugrichText.Clear();
        }


        /// <summary>
        /// 添加LOGO 信息
        /// </summary>
        /// <param name="str"></param>
        private void AddDebugLog(string str)
        {
            if (DebugrichText.InvokeRequired)
            {
                DebugrichText.Invoke(new Action<string>(AddDebugLog), str);
            }
            else
            {
                string DebugString = DateTime.Now.ToString() + "  ";
                DebugString += str + "\r\n";
                DebugrichText.AppendText(DebugString);
            }
        }

        private void DebugForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)  //如果是用户点击右上角关闭按钮
            {
                e.Cancel = true;   //取消操作
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (button1.Text == "停止打印")
            {
                MainForm.PlayDebugString -= AddDebugLog;
                button1.Text = "开始打印";
            }
            else
            {
                MainForm.PlayDebugString += AddDebugLog;
                button1.Text = "停止打印";
            }
        }
    }
}
